<!--回弹业务数据字典---回弹仪器设备管理---查看-->
<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group
            v-model="radio"
            size="small"
            @change="modelType($event)"
          >
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="yj_searchForm(getList)"
            ></el-button>

            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '3' && yj_edit == true"
              @click="edit('编辑')"
              >编辑</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="small"
              v-if="getList.modelType == '3' && yj_submit == true"
              @click="SubmitText(row)"
              >提交</el-button
            >

            <el-button
              type="primary"
              icon="el-icon-delete"
              size="small"
              v-if="getList.modelType == '3' && yj_delete == true"
              @click="rowDelete(fId)"
              >删除</el-button
            >
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
      <!--配合比通知单编号弹框 查看 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px">
              <div class="baseTitle">场站质量管理网格</div>
              <div class="publicForm" style="height: 80px">
                <publicForm
                  lableWidth="115px"
                  :formObj="formObjShow"
                  :formData="formData"
                >
                </publicForm>
              </div>

              <div
                style="
                  width: 100%;
                  display: flex;
                  justify-content: space-between;
                "
              >
                <div style="width: 50%">
                  <div class="baseTitle">项目部质量责任人</div>
                  <div class="publicForm" style="height: 170px">
                    <publicForm
                      lableWidth="115px"
                      :formObj="projectShow"
                      :formData="formData"
                    >
                    </publicForm>
                  </div>
                </div>
                <div style="width: 50%">
                  <div class="baseTitle">监理质量责任人</div>
                  <div class="publicForm" style="height: 170px">
                    <publicForm
                      lableWidth="115px"
                      :formObj="supervisionShow"
                      :formData="formData"
                    >
                    </publicForm>
                  </div>
                </div>
              </div>

              <div class="baseTitle">总工审核</div>
              <div class="publicForm" style="height: 80px">
                <publicForm
                  lableWidth="115px"
                  :formObj="examineShow"
                  :formData="formData"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>

              <div class="baseTitle">开工信息管理</div>
              <div class="publicForm" style="height: 80px">
                <publicForm
                  ref="publicForm"
                  lableWidth="115px"
                  :formObj="informationShow"
                  :formData="formData"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>
              <div style="height: 50px"></div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="yj_saveForm()">保存</el-button>

            <el-button type="warning" @click="dialogEditVisible = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getQualityDutyStationLists, //列表
  getQualityDutyStationByFid, //详情
  workQualityDutyStation, //保存
  commitWorkQualityDutyStation, //提交
  deleteQualityDutyStation, //删除
} from "@/api/request.js";
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项

export default {
  inject: ["reload"],
  name: "startText",
  data() {
    return {
      name: "startText",
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页
      yj_edit: null,
      yj_delete: null,
      yj_submit: null,
      radio: "待办",
      // 列表
      getList: {
        fCompanyid: "", // 查询条件项目名称id
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "3", // 3-待办 4-已办 传2 表示列表页查询
        fQualitygridclass: "", // 上方查询条件质量网格
        fQualitygridtype: "", // 上方查询条件工程网格
        keyWord: "", // 责任人
      },
      fId: null, //当前行数据fId
      loading: false, //列表转载
      table_config: formJs.table_configText,
      tableData: [], //表格列表数据列表
      // 列表

      // 弹框
      timeYMD: null, //当前日期
      btnShow: true,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示

      // 陈妮娜
      formObjShow: formJs.formObjLook, //场站质量管理网格
      supervisionShow: formJs.supervisionLook, //责任人右侧
      projectShow: formJs.projectLook, //责任人左侧--查看
      examineShow: formJs.examineLook, //总工审核--查看
      informationShow: null, //开工
      information: formJs.information,
      informationLook: formJs.informationLook,
      Sign: "",

      // 陈妮娜

      formData: formJs.formData,
      saveData: null,

      // 弹框

      userInfo: {}, //登录用户
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    publicForm, //表单
  },
  created() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
  },
  mounted() {
    this.getList = {
      fCompanyid: this.userInfo.companyId, // 查询条件项目名称id
      page: 1, // 当前页码
      pageSize: 20, // 每页显示条数
      userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
      modelType: "3", // 3-待办 4-已办 传2 表示列表页查询
      fQualitygridclass: "", // 上方查询条件质量网格
      fQualitygridtype: "", // 上方查询条件工程网格
      keyWord: "", // 责任人
    };
    this.getHeight();
    this.getData();
    this.yj_searchForm(this.getList);
    this.btnRole(this.name);

    this.table_config.operation.cols = [
      {
        prop: "fStatus",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];
    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "审核中") {
        color = "red !important";
      } else if (rowData == "已完成") {
        color = "green !important";
      } else if (rowData == "待开工") {
        color = "#e6a23c !important"; //橙色
      } else {
        color = "#409eff !important"; //蓝色
      }
      return color;
    };
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_delete = btnStr.includes("yj_delete");
        this.yj_submit = btnStr.includes("yj_submit");
      } else {
        this.yj_edit = true;
        this.yj_delete = true;
        this.yj_submit = true;
      }
    },

    modelType(e) {
      this.fId = "";
      if (e == "待办") {
        this.getList.modelType = "3";
        this.getList.userId = this.userInfo.userId;
        this.getList.fCompanyid = this.userInfo.companyId;
      } else {
        this.getList.modelType = "4";
        this.getList.userId = this.userInfo.userId;
        this.getList.fCompanyid = this.userInfo.companyId;
      }
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(id) {
      this.loading = true;
      getQualityDutyStationLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          console.log("列表");
          this.loading = false;
        });
    },

    edit(titel) {
      this.dialogTitle = titel;
      this.btnShow = true;
      this.informationShow = this.information;

      if (this.fId != "" && this.fId != null) {
        if (this.row.fStatus == "待开工") {
          this.loadingEditDialog = true; //弹框loading
          this.dialogEditVisible = true;
          this.getConcrete(this.fId);
        } else {
          return this.$message.error("本条数据不可编辑");
        }
      } else {
        return this.$message.error("请先选择需要编辑的数据");
      }
    },
    // 获取详情
    getConcrete(id) {
      getQualityDutyStationByFid({ fId: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog = false; //弹框loading
            this.formData = res.data.yjQmpMsQualitydutystationManagement;
            if (this.formData.fIswork == null) {
              this.formData.fIswork = "";
            }
            //生产/施工开始时间
            if (
              this.formData.fWorkdates == "" ||
              this.formData.fWorkdates == null
            ) {
              this.formData.fWorkdates = this.timeYMD;
            }
            //填报日期
            if (
              this.formData.fWorkreportdates == "" ||
              this.formData.fWorkreportdates == null
            ) {
              this.formData.fWorkreportdates = this.timeYMD;
            }

            // 填报人
            if (
              this.formData.fWorkreportusername == "" ||
              this.formData.fWorkreportusername == null ||
              this.formData.fWorkreportuserid == "" ||
              this.formData.fWorkreportuserid == null
            ) {
              this.formData.fWorkreportusername = this.userInfo.realName;
              this.formData.fWorkreportuserid = this.userInfo.userId;
            }
          } else {
            console.log("详情接口", res.errcode);
          }
        })
        .catch((err) => {
          console.log(err.msg);
        });
    },
    // 保存
    yj_saveForm() {
      this.fId = "";
      if (this.$refs.publicForm.submitForm()) {
        this.saveData = {
          fId: this.formData.fId, //传入表示修改 不传表示新增
          userId: this.userInfo.userId, //当前登录人id
          userName: this.userInfo.realName, // 当前登录人名称
          fIswork: this.formData.fIswork, //是否开工
          fWorkdates: this.formData.fWorkdates, //生产/施工开始时间
          fWorkreportdates: this.formData.fWorkreportdates, //填报日期
          fWorkreportuserid: this.formData.fWorkreportuserid, //填报人id
          fWorkreportusername: this.formData.fWorkreportusername, //填报人
        };
        workQualityDutyStation(this.saveData)
          .then((res) => {
            if (res.errcode == 0) {
              this.yj_searchForm(this.getList);
              this.dialogEditVisible = false;
              this.$message.success("新增成功");
            } else {
              this.$message.error(res.msg);
              console.log("接口报错");
            }
          })
          .catch((error) => {
            console.log(error);
          });
      } else {
        console.log("error");
      }
    },

    // 提交
    SubmitText(data) {
      if (data.fId != "" && data.fId != null) {
        if (data.fIswork != undefined) {
          if (data.fIswork == "未开工") {
            this.$message.error("本条数据未开工,不可提交");
          } else {
            if (this.row.fWorkreportdates == this.timeYMD) {
              this.$confirm("是否继续提交?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              })
                .then(() => {
                  this.loading = true;
                  commitWorkQualityDutyStation({
                    fId: data.fId,
                    userId: this.userInfo.userId,
                    userName: this.userInfo.realName,
                  })
                    .then((res) => {
                      if (res.errcode == 0) {
                        this.loading = false;
                        this.yj_searchForm(this.getList);
                        this.$message.success("提交成功");
                      } else {
                        this.$message.error("提交失败", res.msg);
                        this.loading = false;
                      }
                    })
                    .catch(() => {
                      console.log("提交失败");
                      this.loading = false;
                    });
                })
                .catch(() => {
                  this.$message("取消提交");
                });
            } else {
              return this.$message.error(
                "请将开工信息管理-填报日期 改为当前日期"
              );
            }
          }
        } else {
          return this.$message.error("本条数据未编辑");
        }
      } else {
        return this.$message.error("请先选择需要提交的数据");
      }
    },

    // 删除
    rowDelete(id) {
      if (id != "" && id != null) {
        this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.loading = true;
            deleteQualityDutyStation({ fId: id })
              .then((res) => {
                if (res.errcode == 0) {
                  this.loading = false;
                  this.yj_searchForm(this.getList);
                  this.$message.success("删除成功");
                } else {
                  this.$message.error("删除失败", res.msg);
                  this.loading = false;
                }
              })
              .catch(() => {
                console.log("删除失败");
                this.loading = false;
              });
          })
          .catch(() => {
            this.$message("取消删除");
          });
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },

    // 获取页面容器高度
    getHeight() {
      var h = document.documentElement.clientHeight; //获取页面可见高度
      this.dialogHeight = h * 0.36 + "px";
    },
    // 点击查看
    yj_viewForm(row, label) {
      this.row = row;
      this.fId = row.fId;
      if (label == "工程网格类别") {
        this.editText(this.fId);
      }
    },

    // 查看
    editText(id) {
      this.dialogTitle = "查看";
      this.informationShow = this.informationLook;
      this.btnShow = false;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getQualityDutyStationByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              this.loadingEditDialog = false; //弹框loading
              this.formData = res.data.yjQmpMsQualitydutystationManagement;
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },

    // 调人员
    selectChange(value, index, prop) {
      // console.log("下拉变", value, index, prop);
      return value, index, prop;
    },
    inputChange(value, index, prop) {
      // console.log("input变", value, index, prop);
      return value, index, prop;
    },
    inputFocus(index, prop) {
      // console.log("input获焦", index, prop);
      return index, prop;
    },
    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
    },
    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>

<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
/* 弹框 */

.mouldForm /deep/ .el-col-12 .el-form-item:first-child .el-input__suffix {
  left: 84% !important;
}
.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 120px !important;
}
/* 弹框 */
</style>